const cheerio = require("cheerio");
//npm install cheerio
const http = require("http");

http.get("http://localhost:3000", (res) => {
    //读取页面文件
    let str = "";
    res.on("data", (chunk) => {
        str += chunk;
    })
    res.on("end", () => {
        // console.log(str);
        let $ = cheerio.load(str);
        console.log($(".newslist li").length);//4
        let len = $(".newslist li").length;
        for (let i = 0; i < len; i++) {
            console.log($(".newslist li").eq(i).html());
            $(".newslist li").attr("class", "bg");
        }
    })
    //cheerio解析
})